<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
</head>

<body>
    <div id="root">
        <h2>watch的使用</h2>
        <p>{{fullname}}</p>
    </div>
    <script>
        Vue.config.productionTip = false;	 // 阻止 Vue在启动时生成生产提示
        /* 
        使用watch来书写获取全名的逻辑,感受watch和computed的区别
        */
        const vm = new Vue({
            el: "#root", // 挂载的容器
            data() { // 数据
                return {
                    firstname:'li',
                    lastname:'si',
                    fullname:''
                }
            },
            watch:{
                firstName:{
                    immediate:true, // 立即监听
                    deep:true, // 深度监听
                    handler(){
                        this.fullname = this.firstname + ' ' + this.lastname
                    }
                },
                lastName:{
                    immediate:true, //立即监听
                    deep:true, // 深度监听
                    handler(){
                        this.fullname = this.firstname + ' ' + this.lastname
                    }
                }
            }
        })
</script>
</body>

</html>